home *** CD-ROM | disk | FTP | other *** search
/ Programming Microsoft Visual Basic .NET / Programming Microsoft Visual Basic .NET (Microsoft Press)(X08-78517)(2002).bin / setup / vbnet / 16 windows forms / windowsformsdemo / anchorform.vb < prev    next >
Encoding:
Text File  |  2002-03-16  |  6.5 KB  |  162 lines

  1. Public Class AnchorForm
  2.     Inherits System.Windows.Forms.Form
  3.  
  4. #Region " Windows Form Designer generated code "
  5.  
  6.     Public Sub New()
  7.         MyBase.New()
  8.  
  9.         'This call is required by the Windows Form Designer.
  10.         InitializeComponent()
  11.  
  12.         'Add any initialization after the InitializeComponent() call
  13.  
  14.     End Sub
  15.  
  16.     'Form overrides dispose to clean up the component list.
  17.     Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
  18.         If disposing Then
  19.             If Not (components Is Nothing) Then
  20.                 components.Dispose()
  21.             End If
  22.         End If
  23.         MyBase.Dispose(disposing)
  24.     End Sub
  25.         Friend WithEvents Button2 As System.Windows.Forms.Button
  26.         Friend WithEvents TextBox1 As System.Windows.Forms.TextBox
  27.     Friend WithEvents TextBox2 As System.Windows.Forms.TextBox
  28.     Friend WithEvents CheckBox1 As System.Windows.Forms.CheckBox
  29.     Friend WithEvents CheckBox2 As System.Windows.Forms.CheckBox
  30.     Friend WithEvents Button1 As System.Windows.Forms.Button
  31.     Friend WithEvents Button3 As System.Windows.Forms.Button
  32.     Friend WithEvents Label1 As System.Windows.Forms.Label
  33.  
  34.     'Required by the Windows Form Designer
  35.     Private components As System.ComponentModel.Container
  36.  
  37.     'NOTE: The following procedure is required by the Windows Form Designer
  38.     'It can be modified using the Windows Form Designer.  
  39.     'Do not modify it using the code editor.
  40.     <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
  41.         Me.Button2 = New System.Windows.Forms.Button()
  42.         Me.Button3 = New System.Windows.Forms.Button()
  43.         Me.TextBox1 = New System.Windows.Forms.TextBox()
  44.         Me.CheckBox1 = New System.Windows.Forms.CheckBox()
  45.         Me.CheckBox2 = New System.Windows.Forms.CheckBox()
  46.         Me.TextBox2 = New System.Windows.Forms.TextBox()
  47.         Me.Button1 = New System.Windows.Forms.Button()
  48.         Me.Label1 = New System.Windows.Forms.Label()
  49.         Me.SuspendLayout()
  50.         '
  51.         'Button2
  52.         '
  53.         Me.Button2.Location = New System.Drawing.Point(384, 128)
  54.         Me.Button2.Name = "Button2"
  55.         Me.Button2.Size = New System.Drawing.Size(80, 32)
  56.         Me.Button2.TabIndex = 1
  57.         Me.Button2.Text = "Cancel"
  58.         '
  59.         'Button3
  60.         '
  61.         Me.Button3.Location = New System.Drawing.Point(384, 168)
  62.         Me.Button3.Name = "Button3"
  63.         Me.Button3.Size = New System.Drawing.Size(80, 32)
  64.         Me.Button3.TabIndex = 0
  65.         Me.Button3.Text = "OK"
  66.         '
  67.         'TextBox1
  68.         '
  69.         Me.TextBox1.Location = New System.Drawing.Point(8, 24)
  70.         Me.TextBox1.Name = "TextBox1"
  71.         Me.TextBox1.Size = New System.Drawing.Size(352, 20)
  72.         Me.TextBox1.TabIndex = 3
  73.         Me.TextBox1.Text = ""
  74.         '
  75.         'CheckBox1
  76.         '
  77.         Me.CheckBox1.Location = New System.Drawing.Point(8, 64)
  78.         Me.CheckBox1.Name = "CheckBox1"
  79.         Me.CheckBox1.Size = New System.Drawing.Size(104, 16)
  80.         Me.CheckBox1.TabIndex = 5
  81.         Me.CheckBox1.Text = "Anchor Controls"
  82.         '
  83.         'CheckBox2
  84.         '
  85.         Me.CheckBox2.Location = New System.Drawing.Point(128, 64)
  86.         Me.CheckBox2.Name = "CheckBox2"
  87.         Me.CheckBox2.Size = New System.Drawing.Size(216, 16)
  88.         Me.CheckBox2.TabIndex = 6
  89.         Me.CheckBox2.Text = "Enforce Min/Max Size"
  90.         '
  91.         'TextBox2
  92.         '
  93.         Me.TextBox2.Location = New System.Drawing.Point(8, 96)
  94.         Me.TextBox2.Multiline = True
  95.         Me.TextBox2.Name = "TextBox2"
  96.         Me.TextBox2.Size = New System.Drawing.Size(352, 104)
  97.         Me.TextBox2.TabIndex = 4
  98.         Me.TextBox2.Text = "Click on the checkbox to anchor controls, then resize and maximize this form"
  99.         '
  100.         'Button1
  101.         '
  102.         Me.Button1.Location = New System.Drawing.Point(384, 16)
  103.         Me.Button1.Name = "Button1"
  104.         Me.Button1.Size = New System.Drawing.Size(80, 32)
  105.         Me.Button1.TabIndex = 2
  106.         Me.Button1.Text = "Save"
  107.         '
  108.         'Label1
  109.         '
  110.         Me.Label1.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D
  111.         Me.Label1.Dock = System.Windows.Forms.DockStyle.Bottom
  112.         Me.Label1.Location = New System.Drawing.Point(0, 213)
  113.         Me.Label1.Name = "Label1"
  114.         Me.Label1.Size = New System.Drawing.Size(472, 16)
  115.         Me.Label1.TabIndex = 7
  116.         Me.Label1.Text = "A docked Label control "
  117.         Me.Label1.TextAlign = System.Drawing.ContentAlignment.MiddleCenter
  118.         '
  119.         'AnchorForm
  120.         '
  121.         Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
  122.         Me.ClientSize = New System.Drawing.Size(472, 229)
  123.         Me.Controls.AddRange(New System.Windows.Forms.Control() {Me.Label1, Me.CheckBox2, Me.CheckBox1, Me.TextBox2, Me.TextBox1, Me.Button1, Me.Button2, Me.Button3})
  124.         Me.Name = "AnchorForm"
  125.         Me.Text = "Anchor and Dock  Property"
  126.         Me.ResumeLayout(False)
  127.  
  128.     End Sub
  129.  
  130. #End Region
  131.  
  132.     Private Sub CheckBox1_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CheckBox1.CheckedChanged
  133.         If CheckBox1.Checked Then
  134.             ' enforce anchoring for all controls
  135.             TextBox1.Anchor = AnchorStyles.Top Or AnchorStyles.Left Or AnchorStyles.Right
  136.             TextBox2.Anchor = AnchorStyles.Left Or AnchorStyles.Right Or AnchorStyles.Top Or AnchorStyles.Bottom
  137.             Button1.Anchor = AnchorStyles.Top Or AnchorStyles.Right
  138.             Button2.Anchor = AnchorStyles.Bottom Or AnchorStyles.Right
  139.             Button3.Anchor = AnchorStyles.Bottom Or AnchorStyles.Right
  140.         Else
  141.             ' disable anchoring for all controls
  142.             TextBox1.Anchor = AnchorStyles.Top Or AnchorStyles.Left
  143.             TextBox2.Anchor = AnchorStyles.Top Or AnchorStyles.Left
  144.             Button1.Anchor = AnchorStyles.Top Or AnchorStyles.Left
  145.             Button2.Anchor = AnchorStyles.Top Or AnchorStyles.Left
  146.             Button3.Anchor = AnchorStyles.Top Or AnchorStyles.Left
  147.         End If
  148.     End Sub
  149.  
  150.     Private Sub CheckBox2_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CheckBox2.CheckedChanged
  151.         If CheckBox1.Checked Then
  152.             ' enforce min/max size for this form
  153.             Me.MaximumSize = New System.Drawing.Size(700, 460)
  154.             Me.MinimumSize = New System.Drawing.Size(300, 240)
  155.         Else
  156.             ' don't enforce min/max size
  157.             Me.MaximumSize = Nothing
  158.             Me.MinimumSize = Nothing
  159.         End If
  160.     End Sub
  161. End Class
  162.